import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * Created by BerkBozkurt on 14.5.2015.
 */
public class LifeView extends JPanel {

    private int life;
    private BufferedImage heart;
    public LifeView() {
        super();
        life = 3;
        setVisible(true);
        setSize(66, 22);
        setOpaque(false);
        BufferedImage img = null;
        try {
            img = ImageIO.read(new File("resources/heartIcon.png"));
        } catch (IOException e) {
            System.out.println("Cant find img");
            e.printStackTrace();
        }
        heart = img;

    }

    public void addLife() {
        life++;
    }

    public void decreaseLife() {
        life--;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        for(int i = 0; i < life; i++) {
            g.drawImage(heart, (i) * 22, 3, null); // see javadoc for more info on the parameters
        }
    }
}
